package com.maxsalad.baidu.service;

import com.alibaba.fastjson.parser.Feature;
import com.maxsalad.baidu.entity.RequestCmd;
import com.maxsalad.baidu.entity.dish.list.ResponseDishListEntity;
import com.maxsalad.common.util.JsonUtil;
import com.maxsalad.common.util.OkHttpUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * Created by Administrator on 2016-3-12.
 */
public class DishService extends BaseService {
    private static final Logger log = LoggerFactory.getLogger(DishService.class);

    /**
     * 提供给合作方查看商户菜单所用
     *
     * @return
     */
    public ResponseDishListEntity getDishAll(String shopId) throws Exception {
        Map param = new HashMap();
        param.put("shop_id", shopId);

        RequestCmd cmd = new RequestCmd();
        cmd.setCmd("dish.show");
        cmd.setSource(getSource());
        cmd.setSecret(getSecret());
        cmd.setTimestamp((int) (System.currentTimeMillis() / 1000L));
        cmd.setTicket(UUID.randomUUID().toString().toUpperCase());
        cmd.setBody(param);

        String sign = getSign(cmd);
        cmd.setSign(sign);
        log.debug(sign);

        String json = OkHttpUtil.post(getBaseUrl(), JsonUtil.serialize(cmd));
        log.debug(json);

        return (ResponseDishListEntity) JsonUtil.deserialize(json, ResponseDishListEntity.class);
    }
}
